package org.example.judge_common.entity;

import lombok.Data;

/**
 * 请求结果返回
 */
@Data
public class ResponseResult {
    /**
     * 返回是否成功
     */
    private boolean success;
    /**
     * 状态码
     */
    private int code;
    /**
     * 提示信息
     */
    private String message;

    /**
     * 返回数据
     */
    private Object data;

    public ResponseResult setData(Object data) {
        this.data = data;
        return this;
    }

    public static ResponseResult info(String message) {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setSuccess(true);
        responseResult.setCode(10000);
        responseResult.setMessage(message);
        return responseResult;
    }

    public static ResponseResult error(int code, String message) {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setSuccess(false);
        responseResult.setCode(code);
        responseResult.setMessage(message);
        return responseResult;
    }


    public static ResponseResult success() {
        return ResponseResult.info("操作成功");
    }

    public static ResponseResult fail(String msg) {
        return ResponseResult.error(10001, msg != null ? msg : "操作失败");
    }

    public static ResponseResult unLogin() {
        return ResponseResult.error(10002, "未登录");
    }

    public static ResponseResult unAuditor() {
        return ResponseResult.error(10003, "权限不足");
    }

    public static ResponseResult serverError() {
        return ResponseResult.error(10004, "系统繁忙");
    }
    public static ResponseResult NotData() {
        return ResponseResult.error(10005, "查无数据");
    }
    public static ResponseResult NotData(String msg) {
        return ResponseResult.error(10005, msg);
    }
}
